package com.cy.pj.sys.controller;

import com.cy.pj.common.util.ShiroUtils;
import com.cy.pj.sys.pojo.SysUser;
import com.cy.pj.sys.pojo.SysUserMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/")
public class PageController {
    @Autowired
    SysMenuService sysUserService;

    @RequestMapping("doIndexUI")

    public String doIndexUI(Model model) {

        SysUser user= ShiroUtils.getUser();
        model.addAttribute("username", user.getUsername());
        List<SysUserMenu> userMenus=
                sysUserService.findUserMenusByUserId(user.getId());
        model.addAttribute("userMenus",userMenus);
        return "starter";
    }

    @RequestMapping("log/log_list")
    public String doLogUI(){
        return "sys/log_list";
    }

    @RequestMapping("doPageUI")
    public String doPageUI(){
        return "common/page";
    }

    @RequestMapping("menu/menu_list")
    public String doMenuUI(){
        return "sys/menu_list";
    }

    @RequestMapping("{module}/{moduleUI}")
    public String doModuleUI(@PathVariable String moduleUI){
        return "sys/"+moduleUI;
    }

    @RequestMapping("doLoginUI")
    public String doLoginUI(){
        return "login";
    }

}
